Homework 3

Choose FIVE of the following eight problems to submit as homework. If you submit fewer than five problems, I will give you partial credit for the problems you do submit.

Each problem must be submitted as its own .cpp file. Grading for each problem is as follows:

If two or more people submit copies of the same work, every person submitting the copied work will get a 0 for the entire homework.

You must write functions outside main for each of the following problems for full credit.

    Functions

  1. Write a complete C++ function that does the following:
  2. Sample run of program:
    Enter a number with five or more digits: 25361 Your original number is: 25361 The gap sum is 13 The original number minus the gap sum is 25348
  3. Write a complete C++ program that does the following:
  4. Sample run of program:
    Enter a number between 4 and 16: 3 Bad input! Try again: 2 Bad input! Try again: 1 Would you like a triangle or a square? triangle * ** *** **** ***** ****** ******* ******** ********* **********

    Another sample run of program:
    Enter a number between 4 and 16: 5 Would you like a triangle or a square? square ***** ***** ***** ***** *****
  5. Write a complete C++ program that does the following:
  6. Sample run of program:
    Enter a number with at least three digits: 1233 Mixed parity

    Another sample run of program:
    Enter a number with at least three digits: 22480 All even

    Another sample run of program:
    Enter a number with at least three digits: 333 All odd

    Reference Parameters

  7. Write a complete C++ program that does the following:
  8. Sample run of program:
    Enter three numbers: 1 3 2 Would you like the numbers sorted in ascending or descending order? ascending Your sorted variables now store: a = 1, b = 2, c = 3

    Another sample run of program:
    Enter three numbers: 7 2 4 Would you like the numbers sorted in ascending or descending order? descending Your sorted variables now store: a = 7, b = 4, c = 2
  9. Write a complete C++ program that does the following:
  10. Sample run of program:
    Enter three scores: 87 89 82 The curve is 11. The scores after applying the curve are 98, 100, 93.

    Recursion

  11. Write a complete C++ function that does the following:
  12. Sample run of program:
    Enter a number greater than or equal to 100: 2336 The sum of the first three digits is 8 0 2 4 6 8

    Another sample run of program:
    Enter a number greater than or equal to 100: 19374 The sum of the first three digits is 13 1 3 5 7 9 11 13
  13. Generates the first five to twenty numbers in this sequence: a_0 = 0 (base case); a_{n} = 2*a_{n-1} + 3 (recursive definition).
  14. Sample run of program:
    Enter a number between 5 and 20: 7 0 3 9 21 45 93 189

    Another sample run of program:
    Enter a number between 5 and 20: 12 0 3 9 21 45 93 189 381 765 1533 3069 6141
  15. Write a complete C++ function that does the following:
  16. Sample run of program:
    Enter a number greater than or equal to 3: 23353 removed a 3 removed a 3 removed a 3 22252 I don't like numbers with 3's in them.

    Another sample run of program:
    Enter a number greater than or equal to 3: 5764 5764 I don't like numbers with 3's in them.